import {drizzle} from 'drizzle-orm/mysql2'
import {createPool} from 'mysql2'
import * as schema from '../schema/schema'
import * as relations from '../schema/relations'
import {envPlugin} from './dw'
import {t} from 'elysia'

const _env = envPlugin(
  t.Object({
    DATABASE_URL: t.String(),
  }),
)

const db = drizzle(createPool(_env.DATABASE_URL), {schema: {...schema, ...relations}, mode: 'default'})

export default db

export type DB = typeof db
